<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>网上购票</title>
<link rel="stylesheet" href="resources/css/frozen.css">
<link rel="stylesheet" href="resources/css/main.css">
<style>
.ui-header .ui-btn-right {
	background-color: #8cdaf6;
	height: 44px;
	color: #fff;
	display: block;
	position: absolute;
	top: 0;
	right: 0;
	padding: 0 20px;
}
</style>
<script src="resources/lib/zepto.min.js"></script>
<script src="resources/js/frozen.js"></script>
<script src="resources/js/config.js"></script>
<script src="resources/js/main.js"></script>

</head>
<body ontouchstart="">
	<header class="ui-header ui-header-positive ui-border-b">
		<i class="ui-icon-return" onclick="history.back()"></i>
		<h1>常用联系人</h1>
		<button id="btn-add" class="ui-btn-right">添加</button>
	</header>
	<footer class="ui-footer ui-footer-btn">
		<ul id="footer" class="ui-tiled ui-border-t">
			<li data-href="index.html" class="ui-border-r">
				<div>查询购票</div>
			</li>
			<li data-href="order.html" class="ui-border-r">
				<div>订单查询</div>
			</li>
			<li data-href="member.html">
				<div>会员中心</div>
			</li>
		</ul>
	</footer>
	<section class="ui-container">
		<section id="friend-container" class="ui-selector">
			<header>
				<h3></h3>
			</header>
			<ul id="friend-list" class="ui-list ui-list-text ui-list-cover ui-border-tb">
			</ul>
		</section>
		<div class="ui-whitespace" style="margin-top: 10px;">
			<h1 class="ui-txt-warning">温馨提示：</h1>
			<p class="ui-txt-justify">您的信息也需加入到常用联系人中。</p>
		</div>
		<section id="empty-text" class="ui-container ui-center" style="display: none;">
		</section>
	</section>
	<div id="loading" class="ui-loading-block hide">
		<div class="ui-loading-cnt">
			<i class="ui-loading-bright"></i>
			<p>努力加载中...</p>
		</div>
	</div>

<script>
// 检查登录状态
checkLogin();

(function (){
	/* -------------------- 根据sessionStorage中的值，初始化界面 -------------------- */
	
	if(!!sessionStorage.message) {
		showSuccessTip(sessionStorage.message);
		sessionStorage.message = "";
	}
	
	/* -------------------- 根据localStorage中的值，初始化界面 -------------------- */
	
	// 查询并加载联系人
	showLoading("#loading");
	ajax({
		url: appConfig.baseUrl + "/BusTicketOrder.go",
		data: {
			method: "getMemberFriendsByMember",
			memberId: localStorage.memberId
		},
		failMessage: "查询失败，请重试",
		success: function(data) {
			hideLoading("#loading");
			$("#bus-list").empty();
			if(!!data.rows) {
				if(data.rows.length>0) {
					$("#friend-list").empty();
					
					for(var i=0; i<data.rows.length; i++) {
						var record = data.rows[i];
						$("#friend-list").append(
							"<li class='ui-border-t' friend-id='" + record.Id +
							"' friend-name='" + record.LinkmanName +
							"' id-card='" + record.LinkmanCredit +
							"' mobile='" + record.LinkmanPhone + "'>" +
							record.LinkmanName + "，" + record.LinkmanCredit + "</li>"
						);
					}
				} else {
					$("#empty-text").html("还未添加过联系人");
					$("#empty-text").show();
				}
			} else {
				$("#empty-text").html("查询失败，请重试");
				$("#empty-text").show();
			}
		}
	});
	
	// 添加按钮点击事件
	$("#btn-add").tap(function(){
		location.href = "addFriend.html";
	});
	
	// 起点站列表点击事件
    $(document).on("tap", "#friend-list li", function(){
		var friendDetail = {};
		friendDetailId = $(this).attr("friend-id");
		friendDetailName = $(this).attr("friend-name");
		friendDetailIdCard = $(this).attr("id-card");
		friendDetailMobile = $(this).attr("mobile");
		
		
		sessionStorage.friendDetailId = friendDetailId;
		sessionStorage.friendDetailName = friendDetailName;
		sessionStorage.friendDetailIdCard = friendDetailIdCard;
		sessionStorage.friendDetailMobile = friendDetailMobile;
		location.href = "friendDetail.html";
	});
	
	// 底部主菜单初始化
	initFooter("#footer");
})();
</script>
</body>
</html>